package com.atguigu01.throwable;

import org.junit.Test;

import java.util.Date;
import java.util.Scanner;

/**
 * ClassName: ExceptionTest
 * Package: com.atguigu01.throwable
 * Description:
 *
 * @Author ZY
 * @Create 15:45
 * @Version 1.0
 */
public class ExceptionTest {

    /**
     *ArrayIndexOutOfBoundsException
     * 下标越界异常
     */
    @Test
    public void test1(){
        int[] arr = new int[10];
        System.out.println(arr[10]);
    }

    /**
     * NullPointerException
     * 空指针异常
     */
    @Test
    public void test2(){
//        String str = "hello";
//        str = null;
//        System.out.println(str.toString());

//        int[] arr = new int[10];
//        arr = null;
//        System.out.println(arr[0]);
    }

    /**
     * ClassCastException
     * 类型转换异常
     */
    @Test
    public void test3(){
        Object obj = new String();
//        String str = (String)obj;

        Date date =  (Date) obj;
    }

    /**
     * NumberFormatException
     * 数字格式异常
     */
    @Test
    public void test4(){
        String str = "123";
        str = "abc";
        int i = Integer.parseInt(str);
        System.out.println(i);
    }

    /**
     * InputMismatchException
     * 输入不匹配异常
     */
    @Test
    public void test5(){
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        System.out.println(num);
    }

    /**
     * ArithmeticException
     * 算数异常
     */
    @Test
    public void test6(){
        int num = 10;
        System.out.println(num / 0);
    }
    
    //********************************以上是运行时异常，以下是编译时异常*******************************

    /**
     * ClassNotFoundException
     * 类找不到异常
     */
    @Test
    public void test7(){
//        Class clz = Class.forName("java.lang.String");

    }
    
    
    
}
